package com.example.dao.impl;

import com.example.dao.MenuDao;
import com.example.entity.IndexInfo;
import com.example.utils.BaseDao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class MenuDaoImpl implements MenuDao {
    @Override
    public List<IndexInfo> selectResByUserId(int typeid,int pid) {
        List<IndexInfo>indexInfoList=new ArrayList<>();
        Object[]objects=new Object[2];
        objects[0]=typeid;
        objects[1]=pid;
        ResultSet resultSet = BaseDao.select("select *from resources where type=? and parentId=? ", objects);
        try {
            while (resultSet.next()){
                IndexInfo indexInfo=new IndexInfo();
                indexInfo.setId(resultSet.getInt("id"));
                indexInfo.setIcon(resultSet.getString("icon"));
                indexInfo.setTitle(resultSet.getString("name"));
                indexInfo.setHref( resultSet.getString("resUrl"));
                indexInfoList.add(indexInfo);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return indexInfoList;
    }
}
